package com.ruoyi.business.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.business.mapper.ContentMapper;
import com.ruoyi.business.domain.Content;
import com.ruoyi.business.service.IContentService;

import javax.annotation.Resource;

/**
 * ContentService业务层处理
 *
 * @author win
 * @date 2021-06-14
 */
@Service
public class ContentServiceImpl implements IContentService
{
    @Autowired
    private ContentMapper contentMapper;

    @Resource
    private IdWorker idWorker;

    /**
     * 查询Content
     *
     * @param id ContentID
     * @return Content
     */
    @Override
    public Content selectContentById(Long id)
    {
        return contentMapper.selectContentById(id);
    }

    /**
     * 查询Content列表
     *
     * @param content Content
     * @return Content
     */
    @Override
    public List<Content> selectContentList(Content content)
    {
        return contentMapper.selectContentList(content);
    }

    @Override
    public List<Content> selectAuditContentList(Content content)
    {
        return contentMapper.selectAuditContentList(content);
    }

    /**
     * 新增Content
     *
     * @param content Content
     * @return 结果
     */
    @Override
    public int insertContent(Content content)
    {
        content.setId(idWorker.nextId());
        if (content.getCreateTime() == null) {
            content.setCreateTime(DateUtils.getNowDate());
        }
        content.setCreateBy(SecurityUtils.getUsername());
        return contentMapper.insertContent(content);
    }

    /**
     * 修改Content
     *
     * @param content Content
     * @return 结果
     */
    @Override
    public int updateContent(Content content)
    {
        if (content.getUpdateTime() == null) {
            content.setUpdateTime(DateUtils.getNowDate());
        }
        content.setUpdateBy(SecurityUtils.getUsername());
        return contentMapper.updateContent(content);
    }

    /**
     * 批量删除Content
     *
     * @param ids 需要删除的ContentID
     * @return 结果
     */
    @Override
    public int deleteContentByIds(Long[] ids)
    {
        return contentMapper.deleteContentByIds(ids);
    }

    /**
     * 删除Content信息
     *
     * @param id ContentID
     * @return 结果
     */
    @Override
    public int deleteContentById(Long id)
    {
        return contentMapper.deleteContentById(id);
    }

    @Override
    public List<Content> selectContentListByCategoryIds(List<Long> categoryIds) {
        return contentMapper.selectContentListByCategoryIds(categoryIds);
    }

    @Override
    public List<Content> selectContentListByCategoryIds(List<Long> categoryIds, Integer limit) {
        return contentMapper.selectContentListByCategoryIdsAndLimit(categoryIds, limit);
    }

    @Override
    public List<Content> selectContentListByDepartId(Long departId){
        return contentMapper.selectContentListByDepartId(departId);
    }
}
